/** This class provides an access interface for all plugins. 
 *  @author Copyright (c) 2004-2005 by chrmac@gmx.de */

package info.chrm.jtalker;

import java.util.ArrayList;
import java.util.Hashtable;

/** This class provides an access interface for all plugins.
 *  @author ChrM */
public class JTalkerClientPluginConnector {
	private JTalkerClientFront parent;

	public JTalkerClientPluginConnector(JTalkerClientFront _parent) {
            this.parent = _parent;
	}

	public boolean sendMessage(String _content,
				   String _to,
				   String _type,
				   String _description,
                                   String _id) {
		
            return this.parent.theClient.sendMessage(_content, _to, _type, _description, _id);
	}


	public boolean isClientOnline() {
            return this.parent.isConnected;		
	}

	public boolean savePlugInSettings(JTalkerClientPlugInInterface _plugin, Hashtable<String, String> _settings) {
            // TODO: let plugin save own settings
            return false;
	}

        public Hashtable<String, String> readPlugInSettings(JTalkerClientPlugInInterface _plugin) {
            // TODO: get plugin settings
            return null;
        }

	public String getUserName() {
            return this.parent.theClient.userName;
	}

	public String getServerName() {
            return this.parent.theClient.serverName;
	}

	public boolean createServerAccount(String _new_name,
					   String _new_pass) {
            return this.parent.theClient.createNewAccount(_new_name, _new_pass);
	}

	public boolean openURLInBrowser(String _url) {
            return this.parent.openBrowser(_url);
	}

        public ArrayList<String> getOnlineUsers() {
            ArrayList<String> retList = new ArrayList<String>();
            String tmpName;

            for( int i = 0; i < this.parent.theClient.allMembers.size(); i++ ) {
                tmpName = ((JTalkerClient.MemberData)this.parent.theClient.allMembers.get(i)).short_name;
                // Exclude the user himself
                if(!tmpName.equals(this.getUserName()))
                    retList.add(tmpName);	  
            }

            return retList;
        }

        public void registerForCommandResponse(JTalkerClientCommandInterface _object) {
            this.parent.theClient.registerForCommandResponse(_object);
        }
        
        public void deRegisterForCommandResponse(JTalkerClientCommandInterface _object) {
            this.parent.theClient.deRegisterForCommandResponse(_object);
        }
}

